import logging

from selenium.webdriver.common.by import By

from pageobj import BasePage
from settings import host

logger = logging.getLogger(__name__)


class LoginPage(BasePage):
    """登录页面"""

    url = host + '/customer/account/login'

    # 账号（邮箱地址）
    username = (By.ID, 'email')
    # 密码
    password = (By.ID, 'pass')
    # 登录按钮
    loginBtn = (By.ID, 'js_registBtn')

    def login(self, username: str, password: str):
        """login

        :param username:
        :param password:
        :return:
        """
        logger.info('开始登录')
        logger.debug('1.打开登录页面')
        self.open(self.url)
        logger.debug('2.输入账号密码')
        self.input(self.username, username)
        self.input(self.password, password)
        logger.debug('3.点击登录按钮')
        self.click(self.loginBtn)
        logger.debug('4.登录页面跳转')
        self.url_changes(self.url)
